layui.use(['form','table','jquery','layer'],function () {
    var $ = layui.jquery;
    var form = layui.form;
    var table = layui.table;
    var layer = layui.layer;

    select("","");
    function select(feedbackType,feedbackStatus) {
        table.render({
            elem:"#root",
            url:"/Feedback/selectUserFeedBack?feedbackType="+feedbackType+"&feedbackStatus="+feedbackStatus,
            toolbar:"#lefttool",
            page:true,
            limit:5,
            limits:[5,10,15,20],
            size: 'lg',
            cols:[[
                {type:'checkbox',align:"center"},
                {field:"feedbackId",title:"编号",align:"center"},
                {field:"feedbackType",title:"反馈类型",align:"center",templet:function (data) {
                        if(data.feedbackType==2){
                            return "视频反馈";
                        }else if(data.feedbackType==3){
                            return "商品反馈";
                        }else{
                            return "其他反馈";
                        }
                    }},
                {field:"feedbackContent",title:"反馈内容",align:"center"},
                {field:"feedbackStatus",title:"审核状态",align:'center',height:50,templet:function (data) {
                        if(data.feedbackStatus==2){
                            return '已提交';
                        }else if(data.feedbackStatus==3){
                            return "待审核";
                        }else if(data.feedbackStatus==4){
                            return "审核通过"+"<p><a href='javascript:chakan("+data.feedbackId+");'style='color: #0EAA9E'>审核详情</a></p>";
                        }else if(data.feedbackStatus==5){
                            return "未提交";
                        }else{
                            return "审核驳回";
                        }
                    }},
                {title:"操作",align:"center",templet:function (data) {
                    if(data.feedbackStatus==4){
                        return "<div>"+
                           "<a href='javascript:shanchu("+data.feedbackId+");' style='color: #0EAA9E;margin-right: 10px'>删除</a>"
                            +"</div>"
                    }else{
                        return "<div>"+
                            "<a href='javascript:shenhe(\""+data.feedbackId+"\",\""+data.feedbackType+"\",\""+data.feedbackContent+"\");' style='color: #0EAA9E;margin-right: 10px'>审核</a>"
                            +"<a href='javascript:shanchu("+data.feedbackId+");' style='color: #0EAA9E;margin-right: 10px'>删除</a>"
                            +"</div>"
                    }
                }}
            ]]
        })
    };
    //搜索
    $("#sousuo").click(function () {
        var feedbackType = $("#feedbackType").val();
        var feedbackStatus = $("#feedbackStatus").val();
        if(feedbackType=="视频反馈"){
            feedbackType = 2;
        }else if(feedbackType=="商品反馈"){
            feedbackType = 3 ;
        }else if (feedbackType == "其他反馈") {
            feedbackType = 4;
        }else{
            feedbackType = ""
        }
        select(feedbackType,feedbackStatus);
    });
    //重置
    $("#chongzhi").click(function () {
        select("","");
    });
    //查看审核详情
    chakan = function chakan(feedbackId){
        $.ajax({
            type:"post",
            javaType:"json",
            data:{"feedbackId":feedbackId},
            url:"/Feedback/selectUserFeedBackById",
            success:function (data) {
                kan(data);
            }
        })
    };
    function kan(data){
        var obj;
        layer.open({
            type:2,
            shode:0,
            maxmin:true,
            content:"/feedback/feedback-see.html",
            area:['600px', '540px'],
            btn:["确定"],
            yes:function(index){
                layer.close(index);
            },
            success:function (layero,index) {
                obj = layero.find('iframe').contents();
                //console.log(data);
                obj.find("#feedbackId").val(data.data.feedbackId);
                var feedbackType = data.data.feedbackType;
                if(feedbackType==2){
                    feedbackType =  "视频反馈";
                }else if(feedbackType==3){
                    feedbackType = "商品反馈";
                }else{
                    feedbackType = "其他反馈";
                }
                obj.find("#feedbackType").val(feedbackType);
                obj.find("#feedbackContent").val(data.data.feedbackContent);
                obj.find("#createDate").val(data.data.createDate);
                var feedbackStatus = data.data.feedbackStatus;
                if(feedbackStatus==2){
                    feedbackStatus =  '已提交';
                }else if(data.feedbackStatus==3){
                    feedbackStatus =  "待审核";
                }else if(data.feedbackStatus==4){
                    feedbackStatus = "审核通过";
                }else if(data.feedbackStatus==5){
                    feedbackStatus = "未提交";
                }else{
                    feedbackStatus = "审核驳回";
                }
                obj.find("#feedbackStatus").val(feedbackStatus);
                obj.find("#trueName").val(data.data.trueName);
                obj.find("#updateDate").val(data.data.updateDate);
            }
        })
    }

    //审核
    shenhe = function shenhe(feedbackId,feedbackType,feedbackContent){
        var feedbackType = "";
        if(feedbackType==2){
            feedbackType =  "视频反馈";
        }else if(feedbackType==3){
            feedbackType = "商品反馈";
        }else{
            feedbackType = "其他反馈";
        }

        var obj;
        layer.open({
            type:2,
            shode:0,
            maxmin:true,
            title:"反馈审核",
            content:"/feedback/feedback-commodity-audit.html",
            area:['460px','390px'],
            btn:["确定","取消"],
            yes:function(index){
                var feedbackId = localStorage.getItem("feedbackId");
                var feedbackType = $("#feedbackType").text();
                if(feedbackType=="视频反馈"){
                    feedbackType = 2;
                }else if(feedbackType == "商品反馈"){
                    feedbackType = 3;
                }else{
                    feedbackType = 4;
                }
                var updateId = localStorage.getItem("createId");
                var feedbackStatus = localStorage.getItem("feedbackStatus");
                //console.log(feedbackStatus);
                var updateDate = new Date();
                updateDate = getTime(updateDate);
                var remarks = $("#remarks").val();
                var json = {
                    feedbackId:feedbackId,
                    feedbackType:feedbackType,
                    feedbackStatus:feedbackStatus,
                    updateId:updateId,
                    updateDate:updateDate,
                    remarks:remarks
                };
               //console.log(json);
                $.ajax({
                    type:"post",
                    url:"/Feedback/updateUserFeedStatu",
                    dataType:"json",
                    data:json,
                    success:function (data) {
                        if(data){
                            layer.msg("审核成功");
                            layer.close(index);
                        }else{
                            layer.msg("审核失败");
                            layer.close(index);
                        }
                        location.reload();
                    }
                });
            },
            btn2:function(index){
                layer.close(index);
            },
            success:function (layero,index) {
                obj = layero.find("iframe").contents();
                localStorage.setItem("feedbackId",feedbackId);
                obj.find("#feedbackType").text(feedbackType);
                obj.find("#feedbackContent").text(feedbackContent);
            }
        });
    };

    //删除
    shanchu = function shanchu(feedbackId) {
        layer.confirm('是否确定删除此条数据', {
                icon: 3, title: '提示'
            },
            function (index) {
                //通过id删除表格数据
                $.ajax({
                    type:"post",
                    dataType:"json",
                    data:{"feedbackId":feedbackId},
                    url:"/Feedback/delUserFeedBack",
                    success:function (data) {
                        if(data){
                            layer.msg("删除成功");
                            location.reload();
                        }else{
                            layer.msg("删除失败");
                        }
                    }
                });
            }
        )
    };

    //顶部时间
    function getTime(date){
        var year = date.getFullYear(); //获取完整的年份(4位,1970-????)
        var month = date.getMonth()+1; //获取当前月份(0-11,0代表1月)
        var today = date.getDate(); //获取当前日(1-31)
        var hour = date.getHours(); //获取当前小时数(0-23)
        var minute = date.getMinutes(); //获取当前分钟数(0-59)
        var second = date.getSeconds(); //获取当前秒数(0-59)
        var nowTime;
        nowTime = year+'-'+fillZero(month)+'-'+fillZero(today)+' '+fillZero(hour)+':'+fillZero(minute)+':'+fillZero(second);
        return nowTime;
    };

    //时间的为零操作
    function fillZero(str){
        var realNum;
        if(str<10){
            realNum	= '0'+str;
        }else{
            realNum	= str;
        }
        return realNum;
    };

    $("#shuaxin").click(function () {
        location.reload();
    });
    //跳转
        goBack=function goBack(){
            //通过页面查找iframe
            parent.$('#recordLog').val($('#examine').text());
            parent.before();
            return false;
        };
});
